use "actions T1 - T6.dta", clear

**** Table 7 for Bare communication (upper panels)

tab message OwnAction if treatment==3
tab message OwnAction if treatment==4

**** Table 7 for Rich communication (bottom panels)


drop message
save action, replace

use "chat rich communication.dta", clear

drop if Period==.

****  message C
gen KAK=1 if KAKat<6
gen CHK=1 if CHKat<6

**** 6 means message A 
**** 7 means message B

replace KAK=6 if KAKat==6
replace CHK=6 if CHKat==6

replace KAK=7 if KAKat==7
replace CHK=7 if CHKat==7


gen type=0
replace type=KAK if KAK==CHK

rename SubjectID Subject

sort session Period Subject

gen message =0
replace message=3 if type==1 
replace message=2 if type==7
replace message=1 if type==6

keep session Period Subject  seq TimeStamp message

sort session Period Subject

joinby session Period Subject using "action", unmatched(both)

replace message=0 if message==.

keep if treatment>4


 sort session Period Subject seq
 by session Period Subject: replace message=message[_n-1] if message==0&_n>1

 
 
 
 by session Period Subject: keep if _n==_N

tab message OwnAction if treatment==5
tab message OwnAction if treatment==6

 
 
 
 
 
 
 
 